<!DOCTYPE html>
<html lang="en">
<head>
    <!-- The jQuery library is a prerequisite for all jqSuite products -->
    <script type="text/ecmascript" src="../../../js/jquery.min.js"></script>
    <!-- This is the Javascript file of jqGrid -->
    <script type="text/ecmascript" src="../../../js/trirand/jquery.jqGrid.min.js"></script>
    <!-- This is the localization file of the grid controlling messages, labels, etc. -->
    <!-- We support more than 40 localizations -->
    <script type="text/ecmascript" src="../../../js/trirand/i18n/grid.locale-en.js"></script>
	<!-- Load pdfmake lib files -->
	<script type="text/javascript" language="javascript" src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.34/build/pdfmake.min.js">	</script>
	<script type="text/javascript" language="javascript" src="//cdn.rawgit.com/bpampuch/pdfmake/0.1.34/build/vfs_fonts.js"></script>

    <!-- A link to a jQuery UI ThemeRoller theme, more than 22 built-in and many more custom -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/jquery-ui.css" />
    <!-- The link to the CSS that the grid needs -->
    <link rel="stylesheet" type="text/css" media="screen" href="../../../css/trirand/ui.jqgrid.css" />
    <meta charset="utf-8" />
    <title>jqGrid Export to CSV, PDF, Excel</title>
</head>
<body>

  <table id="jqGrid"></table>
	<button id="export">Conditional Export</button>


	<script type="text/javascript">

		$(document).ready(function () {
			$("#jqGrid").jqGrid({
				url: 'data.json',
				datatype: "json",
				colModel: [
					{ label: 'Category Name', name: 'CategoryName', width: 75 },
					{ label: 'Product Name', name: 'ProductName', width: 90 },
					{ label: 'Country', name: 'Country', width: 100 },
					{
						label: 'Price',
						name: 'Price',
						width: 80,
						sorttype: 'number',
						formatter: 'number',
						align: 'right'
					},
					{
						label: 'Quantity',
						name: 'Quantity',
						width: 80,
						sorttype: 'integer',
						formatter : function( value, options) {
							if( options.isExported) {
								if(options.exporttype === 'pdf') {
									return "(" + value + ")";
								}
							}
							return value;
						}
					}
                ],
								loadonce: true,
								viewrecords: true,
                footerrow: true,
                userDataOnFooter: true, // use the userData parameter of the JSON response to display data on footer
                width: 780,
                height: 200,
                rowNum: 150
            });

			$("#export").on("click", function(){
				$("#jqGrid").jqGrid("exportToPdf",{
					title: 'jqGrid Export to PDF',
					orientation: 'portrait',
					pageSize: 'A4',
					description: 'description of the exported document',
					customSettings: null,
					download: 'download',
					includeLabels : true,
					includeGroupHeader : true,
					includeFooter: true,
					fileName : "jqGridExport.pdf"
				})
			})
        });

    </script>

    <!-- This code is related to code tabs -->
    <br />
    <span style="font-size: 12px; font-family: Tahoma">Click on the Tabs below the see the relevant code for the example:</span>
    <br /><br />
    <div id="codetabs" style="width:700px; height: 400px; font-size:65%;"></div>
    <script type="text/ecmascript" src="../../../js/jquery-ui.min.js"></script>
    <script type="text/ecmascript" src="../../../js/prettify/prettify.js"></script>
    <link rel="stylesheet" href="../../../css/prettify.css" />
        <script type="text/ecmascript" src="../../../js/codetabs.js"></script><script type="text/ecmascript" src="../../../js/themeswitchertool.js"></script>

    <script type="text/javascript">

        var tabData =
            [
                { name: "HTML", url: "index.html", lang: "lang-html" },
                { name: "Data.JSON", url: "data.json", lang: "lang-json" },
				{ name: "Description", url: "description.html", lang: "lang-html" },
            ];

        codeTabs(tabData);

    </script>
    <!-- End of code related to code tabs -->
</body>
</html>
